What is is-plain-obj?
The is-plain-obj package is a simple and lightweight npm package used to check if a given object is a plain object, that is, an object created by the Object constructor or one with a null prototype.
What are is-plain-obj's main functionalities?
Check if an object is a plain object
This feature allows you to verify if a given object is a plain object. It returns true for objects created by the Object constructor or with a null prototype and false for all other types of objects, such as instances of custom classes or built-in JavaScript objects like Map.
const isPlainObj = require('is-plain-obj');
console.log(isPlainObj({foo: 'bar'})); // true
console.log(isPlainObj(new Map())); // false
Other packages similar to is-plain-obj
is-plain-object
Similar to is-plain-obj, is-plain-object checks if a given value is a plain object. However, it might have slightly different internal implementations or dependencies, potentially affecting its performance or compatibility in certain environments.
lodash.isplainobject
Part of the Lodash library, lodash.isplainobject offers similar functionality to is-plain-obj. Lodash is a more extensive utility library, so using this function might bring in more dependencies than needed if you're only interested in checking for plain objects.
is-plain-obj
Check if a value is a plain object
An object is plain if it's created by either {}
, new Object()
, or Object.create(null)
.
Install
$ npm install is-plain-obj
Usage
import isPlainObject from 'is-plain-obj';
import {runInNewContext} from 'node:vm';
isPlainObject({foo: 'bar'});
isPlainObject(new Object());
isPlainObject(Object.create(null));
isPlainObject(runInNewContext('({})'));
isPlainObject([1, 2, 3]);
class Unicorn {}
isPlainObject(new Unicorn());
isPlainObject(Math);
Related
- is-obj - Check if a value is an object
- is - Type check values